package com.itheima.heimatoutiaosso.controller;

import com.itheima.heimatoutiaosso.common.Result;
import com.itheima.heimatoutiaosso.domain.dto.WmUserDto;
import com.itheima.heimatoutiaosso.domain.vo.WmUserVo;
import com.itheima.heimatoutiaosso.service.WmUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("wemedia")
public class WmUserController {

    @Autowired
    private WmUserService wmUserService;

    @PostMapping("login/in")
    public Result login(@RequestBody WmUserDto wmUserDTO){
        log.info("{}",wmUserDTO);
        String token = wmUserService.login(wmUserDTO);
        log.info(token);
        if(token==null){
            return new Result(false,-1,"登录失败",null);
        }
        return new Result(true,200,"登录成功",new WmUserVo(wmUserDTO.getName(),token));
    }


}
